package com.fhnew.app.ui.activity.main;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.MediaPlayer;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.fhnew.app.BuildConfig;
import com.fhnew.app.R;
import com.fhnew.app.global.Constants;
import com.fhnew.app.model.internet.been.B_CommonGames;
import com.fhnew.app.model.internet.model.ThirdGameModel;
import com.fhnew.app.model.internet.model.UserModel;
import com.fhnew.app.ui.activity.AddMoneyActivity;

import com.fhnew.app.ui.activity.HelpActivity;
import com.fhnew.app.ui.activity.recomend.RecommendActivity;
import com.fhnew.app.ui.activity.userinfo.ActivityData;
import com.fhnew.app.ui.activity.WithdrawActivity;
import com.fhnew.app.util.ActivityUtil;
import com.fhnew.app.util.HLog;
import com.fhnew.app.widget.LoadingDialog;
import com.fhnew.app.ui.activity.main.option.GameListOption;
import com.fhnew.app.ui.dialogactivity.HuodongActivity;
import com.fhnew.app.ui.dialogactivity.LoginDiolog;
import com.fhnew.app.ui.dialogactivity.RegisterActivity;
import com.fhnew.app.ui.dialogactivity.SetingActivity;
import com.fhnew.app.util.EventBus.ReloginEvent;
import com.fhnew.app.util.SYSOUtils;
import com.fhnew.app.util.UrlUtils;
import com.fhnew.app.widget.GameListView;
import com.fhnew.app.widget.SignalView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;


/**
 * 程序主界面
 * <p>
 * <p>
 * 2、Control  {@link MainActivity#onCreate(Bundle savedInstanceState)}
 * <p>
 * 3、Model  {@link MainActivity#initInfo()}
 */
public class MainActivity extends
        AppCompatActivity {

    //=============================================================
    //View
    //=============================================================

    private LoadingDialog loadingDialog;
    private ImageView userimg;
    private TextView username;
    private TextView username1;
    private ImageView denglu;
    private ImageView zhuce;
    private TextView sports;
    private TextView youxibi;
    private ImageView shezhi;
    private ImageView remen;
    private TextView qipai;
    private TextView buyu;
    private TextView dianjing;
    private TextView dianzi;
    private TextView zhenren;
    private TextView lottery;
    private ScrollView homeLeftScr;
    private ImageView xiangxia;
    private TextView gonggao;
    private LinearLayout honotelayout;
    private EditText sousuo;

    private ImageView fenxiang;
    private ImageView kefu;
    private ImageView huodong;
    private ImageView xima;
    private ImageView xiaoxi;
    private ImageView baoxianxiang;
    private LinearLayout leftlin;
    private ImageView chongzhi;
    private ImageView tixian;
    private SignalView sinnalview;
    private RelativeLayout qipailayout;
    private RelativeLayout lotterylayout;
    private RelativeLayout buyulayout;
    private RelativeLayout dianjinglayout;
    private RelativeLayout dianzilayout;
    private RelativeLayout zhenrenlayout;
    private RelativeLayout sportslayout;
    private ImageView addmoneyimg;

    private GameListView gameListView;
    private HorizontalScrollView gameListScrollView;

    private MediaPlayer mediaPlayer;
    private WifiInfo wifiInfo;

    private Boolean voiceflag = true;
    private static Boolean isExit = false;
    private InnerRecevier innerReceiver;
    private InnerRecevier innerReceiver1;
    private InnerRecevier innerReceiver2;


    private void initView () {


        loadingDialog = new LoadingDialog((ViewGroup) findViewById(android.R.id.content).getRootView());

        userimg = findViewById(R.id.userimg);
        username = findViewById(R.id.username);
        username1 = findViewById(R.id.username1);
        denglu = findViewById(R.id.denglu);
        zhuce = findViewById(R.id.zhuce);
        sports = findViewById(R.id.sports);
        youxibi = findViewById(R.id.youxibi);
        shezhi = findViewById(R.id.shezhi);
        remen = findViewById(R.id.remen);
        qipai = findViewById(R.id.qipai);
        buyu = findViewById(R.id.buyu);
        dianjing = findViewById(R.id.dianjing);
        dianzi = findViewById(R.id.dianzi);
        zhenren = findViewById(R.id.zhenren);
        lottery = findViewById(R.id.lottery);
        homeLeftScr = findViewById(R.id.home_left_scr);
        xiangxia = findViewById(R.id.xiangxia);
        gonggao = findViewById(R.id.gonggao);
        honotelayout = findViewById(R.id.honotelayout);
        sousuo = findViewById(R.id.sousuo);

        fenxiang = findViewById(R.id.fenxiang);
        kefu = findViewById(R.id.kefu);
        huodong = findViewById(R.id.huodong);
        xima = findViewById(R.id.xima);
        xiaoxi = findViewById(R.id.xiaoxi);
        baoxianxiang = findViewById(R.id.baoxianxiang);
        leftlin = findViewById(R.id.leftlin);
        chongzhi = findViewById(R.id.chongzhi);
        tixian = findViewById(R.id.tixian);
        sinnalview = findViewById(R.id.sinnalview);
        qipailayout = findViewById(R.id.qipailayout);
        lotterylayout = findViewById(R.id.lotterylayout);
        buyulayout = findViewById(R.id.buyulayout);
        dianjinglayout = findViewById(R.id.dianjinglayout);
        dianzilayout = findViewById(R.id.dianzilayout);
        zhenrenlayout = findViewById(R.id.zhenrenlayout);
        sportslayout = findViewById(R.id.sportslayout);
        addmoneyimg = findViewById(R.id.addmoneyimg);

        gameListView = findViewById(R.id.gameListView_MainActivity);
        gameListScrollView = findViewById(R.id.horicontalScrollView_MainActivity_GameList);


        addmoneyimg.setOnClickListener(onClickListener);
        userimg.setOnClickListener(onClickListener);
        username1.setOnClickListener(onClickListener);
        kefu.setOnClickListener(onClickListener);
        username.setOnClickListener(onClickListener);
        denglu.setOnClickListener(onClickListener);
        zhuce.setOnClickListener(onClickListener);
        youxibi.setOnClickListener(onClickListener);
        shezhi.setOnClickListener(onClickListener);
        remen.setOnClickListener(onClickListener);
        qipailayout.setOnClickListener(onClickListener);
        buyulayout.setOnClickListener(onClickListener);
        dianjinglayout.setOnClickListener(onClickListener);
        dianzilayout.setOnClickListener(onClickListener);
        lotterylayout.setOnClickListener(onClickListener);
        zhenrenlayout.setOnClickListener(onClickListener);
        xiangxia.setOnClickListener(onClickListener);
        gonggao.setOnClickListener(onClickListener);
        sousuo.setOnClickListener(onClickListener);
        fenxiang.setOnClickListener(onClickListener);
        huodong.setOnClickListener(onClickListener);
        xima.setOnClickListener(onClickListener);
        xiaoxi.setOnClickListener(onClickListener);
        baoxianxiang.setOnClickListener(onClickListener);
        chongzhi.setOnClickListener(onClickListener);
        tixian.setOnClickListener(onClickListener);
        sportslayout.setOnClickListener(onClickListener);


        if (BuildConfig.CASH) {
            tixian.setVisibility(View.VISIBLE);
        } else {
            tixian.setVisibility(View.GONE);
        }
    }

    private void initInfoView () {
        networkclass();
        if (userModel.isLogin()) {
            denglu.setVisibility(View.GONE);
            zhuce.setVisibility(View.GONE);
            username.setVisibility(View.GONE);
            username1.setVisibility(View.VISIBLE);
            username1.setText(userModel.getUser().userName);
            youxibi.setText(userModel.getUser().money );
        } else {
            denglu.setVisibility(View.VISIBLE);
            zhuce.setVisibility(View.VISIBLE);
            username.setVisibility(View.VISIBLE);
            username1.setVisibility(View.GONE);
            youxibi.setText("0.0");
        }
    }

    private void networkclass () {
        wifiInfo.getLinkSpeed();

        if (wifiInfo.getRssi() > -50) { //信号非常好
            sinnalview.setSignalValue(5);
        } else if (wifiInfo.getRssi() > -70 && wifiInfo.getRssi() < -50) { //信号一般般
            sinnalview.setSignalValue(4);//
        } else if (wifiInfo.getRssi() < -70) {//信号很差
            sinnalview.setSignalValue(3);
        } else {//没信号了
            sinnalview.setSignalValue(1);
        }
    }


    private void btbackground () {
        sports.setBackgroundResource(R.mipmap.gameup);
        lottery.setBackgroundResource(R.mipmap.gameup);
        qipai.setBackgroundResource(R.mipmap.gameup);
        buyu.setBackgroundResource(R.mipmap.gameup);
        dianjing.setBackgroundResource(R.mipmap.gameup);
        dianzi.setBackgroundResource(R.mipmap.gameup);
        zhenren.setBackgroundResource(R.mipmap.gameup);
    }

    private void showAD (B_CommonGames resBanner) {
        if (resBanner == null) return;
        Constants.agentModel = resBanner.getData().getAgentModel();
        //滚动公告
        if (resBanner.getData().getNotices() == null){
            gonggao.setText(" null ");
        }else if (resBanner.getData().getNotices().size() == 1) {
            gonggao.setText(resBanner.getData().getNotices().get(0).getTitle() + "        " + resBanner.getData().getNotices().get(0).getContent() + "               " +
                    "                                " + resBanner.getData().getNotices().get(0).getTitle() + "            " + resBanner.getData().getNotices().get(0).getTitle());
        } else if (resBanner.getData().getNotices().size() > 1) {
            String str = "";
            for (int i = 0; i < resBanner.getData().getNotices().size(); i++) {
                str = str + resBanner.getData().getNotices().get(i).getTitle() + "                 " + resBanner.getData().getNotices().get(i).getContent() + "                      ";
            }
            gonggao.setText(str);
        } else {
            gonggao.setText("  暂未配置 " + "  暂未配置 " + "  暂未配置 " + "  暂未配置 " + "  暂未配置 " + "  暂未配置 " + "  暂未配置 " + "  暂未配置 " + "  暂未配置 " +
                    "  暂未配置 ");
        }
        gonggao.setSelected(true);
    }

    private void refreshGameSelectList (B_CommonGames resBanner) {
        if (resBanner == null) return;
        B_CommonGames.DataBean.OpenGameBean openGameBean = resBanner.getData().getOpenGame();

        //棋牌
        if (openGameBean.getPVP() == 1) {
            qipailayout.setVisibility(View.VISIBLE);
        } else {
            qipailayout.setVisibility(View.GONE);
        }
        //捕鱼
        if (openGameBean.getFISH() == 1) {
            buyulayout.setVisibility(View.VISIBLE);
        } else {
            buyulayout.setVisibility(View.GONE);
        }
        //电竞
        if (openGameBean.getYOPLAY() == 1) {
            dianjinglayout.setVisibility(View.VISIBLE);
        } else {
            dianjinglayout.setVisibility(View.GONE);
        }
        //电子
        if (openGameBean.getRNG() == 1) {
            dianzilayout.setVisibility(View.VISIBLE);
        } else {
            dianzilayout.setVisibility(View.GONE);
        }

        //真人
        if (openGameBean.getLIVE() == 1) {
            zhenrenlayout.setVisibility(View.VISIBLE);
        } else {
            zhenrenlayout.setVisibility(View.GONE);
        }
        //体育
        if (openGameBean.getSPORTS() == 1) {
            sportslayout.setVisibility(View.VISIBLE);
        } else {
            sportslayout.setVisibility(View.GONE);
        }

        ArrayList<B_CommonGames.DataBean.LotteryBean> lotterylist = new ArrayList<>();//彩票
        //筛选彩票是否开放
        for (int i = 0; i < resBanner.getData().getLottery().size(); i++) {
            if (resBanner.getData().getLottery().get(i).getRules_status() == 1) {
                lotterylist.add(resBanner.getData().getLottery().get(i));
            }
        }
        //都没开放，隐藏按钮
        if (lotterylist.size() == 0) {
            lotterylayout.setVisibility(View.GONE);
        } else {
            lotterylayout.setVisibility(View.VISIBLE);
        }


    }


    //=============================================================
    //Control
    //=============================================================

    /**
     * 主页
     *
     * @param savedInstanceState
     */
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        ActivityUtil.fullScreen(this);
        super.onCreate(savedInstanceState);

        this.getWindow().setFlags(0x80000000, 0x80000000);
        setContentView(R.layout.activity_main);

        initView();

        initInfo();
    }


    @Override
    protected void onResume () {
        super.onResume();

        initInfoView();

        voiceflag = true;


        if (!mediaPlayer.isPlaying()) {
            //播放音乐
            mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.bgm);
            //是否循环播放
            mediaPlayer.setLooping(true);
            mediaPlayer.start();
        }
        //home创建广播
        innerReceiver = new InnerRecevier();
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        registerReceiver(innerReceiver, intentFilter);
        //电源键关闭
        innerReceiver1 = new InnerRecevier();
        IntentFilter filter1 = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        registerReceiver(innerReceiver1, filter1);
        //电源键开启
        innerReceiver2 = new InnerRecevier();
        IntentFilter filter2 = new IntentFilter(Intent.ACTION_SCREEN_ON);
        registerReceiver(innerReceiver2, filter2);

    }

    @Override
    protected void onStop () {
        super.onStop();
        if (voiceflag) {
            mediaPlayer.stop();
        }
    }

    @Override
    protected void onDestroy () {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        unregisterReceiver(innerReceiver);
        unregisterReceiver(innerReceiver1);
        unregisterReceiver(innerReceiver2);

        userModel.unRegistListener(userInformationChanged);
        thirdGameModel.unregistThirdGameMoneyChangedListener(thirdGameMoneyChangedListener);
    }


    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick (View view) {
            switch (view.getId()) {
                case R.id.userimg:
                case R.id.username1:
                    voiceflag = false;
                    if (!userModel.isLogin()) {
                        Intent intent = new Intent(MainActivity.this, LoginDiolog.class);
                        startActivity(intent);
                    } else {
                        Intent intentm = new Intent(MainActivity.this, ActivityData.class);
                        startActivity(intentm);
                    }
                    break;
                case R.id.username:
                case R.id.denglu:
                    voiceflag = false;
                    Intent intent2 = new Intent(MainActivity.this, LoginDiolog.class);
                    startActivity(intent2);
                    break;
                case R.id.zhuce:
                    voiceflag = false;
                    Intent intent3 = new Intent(MainActivity.this, RegisterActivity.class);
                    startActivity(intent3);
                    break;
                case R.id.youxibi:
                    break;
                case R.id.shezhi:
                    voiceflag = false;
                    Intent intent4 = new Intent(MainActivity.this, SetingActivity.class);
                    startActivity(intent4);
                    break;

                //======================选择一级游戏=====================================
                case R.id.remen:
                    gameListOption.showGameList(1);
                    btbackground();
                    break;
                case R.id.qipailayout:
                    gameListOption.showGameList(2);
                    btbackground();
                    qipai.setBackgroundResource(R.mipmap.gamedown);
                    break;
                case R.id.buyulayout:
                    gameListOption.showGameList(3);
                    btbackground();
                    buyu.setBackgroundResource(R.mipmap.gamedown);
                    break;
                case R.id.dianjinglayout:
                    gameListOption.showGameList(4);
                    btbackground();
                    dianjing.setBackgroundResource(R.mipmap.gamedown);
                    break;
                case R.id.dianzilayout:
                    gameListOption.showGameList(5);
                    btbackground();
                    dianzi.setBackgroundResource(R.mipmap.gamedown);
                    break;
                case R.id.zhenrenlayout:
                    gameListOption.showGameList(6);
                    btbackground();
                    zhenren.setBackgroundResource(R.mipmap.gamedown);
                    break;
                case R.id.sportslayout:
                    gameListOption.showGameList(7);
                    btbackground();
                    sports.setBackgroundResource(R.mipmap.gamedown);
                    break;
                case R.id.lotterylayout:
                    gameListOption.showGameList(8);
                    btbackground();
                    lottery.setBackgroundResource(R.mipmap.gamedown);
                    break;


                //===================菜单按钮========================================
                case R.id.xiangxia:
                    homeLeftScr.fullScroll(ScrollView.FOCUS_DOWN);
                    break;
                case R.id.gonggao:
                    break;
                case R.id.sousuo:
                    break;
                case R.id.fenxiang:
                    voiceflag = false;
                    if (!userModel.isLogin()) {
                        Intent intent = new Intent(MainActivity.this, LoginDiolog.class);
                        startActivity(intent);
                    } else {
                        startActivity(new Intent(MainActivity.this, RecommendActivity.class));
                    }
                    break;
                case R.id.huodong:
                    voiceflag = false;
                    startActivity(new Intent(MainActivity.this, HuodongActivity.class));
                    break;
                case R.id.xima:
                    break;
                case R.id.kefu:
                    voiceflag = false;
                    if (UrlUtils.isFastClick()) {
                        startActivity(new Intent(MainActivity.this, HelpActivity.class));
                    }
                    break;
                case R.id.xiaoxi:
                    voiceflag = false;
                    if (UrlUtils.isFastClick()) {
                        if (TextUtils.isEmpty(UserModel.Token)) {
                            Intent intent = new Intent(MainActivity.this, LoginDiolog.class);
                            startActivity(intent);
                        } else {
                            Intent intentm = new Intent(MainActivity.this, ActivityData.class);
                            intentm.putExtra("intentm", "intentm");
                            startActivity(intentm);
                        }
                    }
                    break;
                case R.id.baoxianxiang:
                    break;

                //=============充值体现=====================
                case R.id.chongzhi:
                case R.id.addmoneyimg:
                    voiceflag = false;
                    if (!userModel.isLogin()) {
                        Intent intent = new Intent(MainActivity.this, LoginDiolog.class);
                        startActivity(intent);
                    } else {
                        startActivity(new Intent(MainActivity.this, AddMoneyActivity.class));
                    }
                    break;
                case R.id.tixian:
                    voiceflag = false;
                    if (!userModel.isLogin()) {
                        Intent intent = new Intent(MainActivity.this, LoginDiolog.class);
                        startActivity(intent);
                    } else {
                        startActivity(new Intent(MainActivity.this, WithdrawActivity.class));
                    }
                    break;
            }
        }
    };



    private GameListOption.CommendGameChangedListener commendGameChangedListener = new GameListOption.CommendGameChangedListener() {
        @Override
        public void changed (B_CommonGames commonGames) {
            showAD(commonGames);
            refreshGameSelectList(commonGames);
        }
    };

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void Event (ReloginEvent reloginEvent) {
        if (reloginEvent.getMessage().equals("600")) {
            userModel.loginOut();
            startActivity(new Intent(this, LoginDiolog.class));
        }
    }

    private UserModel.UserInformationChanged userInformationChanged = new UserModel.UserInformationChanged() {
        @Override
        public void userInformationChanged () {
            initInfoView();
            if(!userModel.isLogin()){
                Intent intent =new Intent(MainActivity.this,LoginDiolog.class);
                startActivity(intent);
            }
        }
    };

    private ThirdGameModel.ThirdGameMoneyChangedListener thirdGameMoneyChangedListener = new ThirdGameModel.ThirdGameMoneyChangedListener() {
        @Override
        public void myMoneyChanged () {
            if(userModel.isLogin()&& youxibi!=null){
                youxibi.setText(userModel.getUser().money );
            }
        }

        @Override
        public void allThirdGameMoneyChanged () {

        }

        @Override
        public void thirdGameMoneyChanged (int game_id) {

        }
    };


    //=============================================================
    //Model
    //=============================================================

    private GameListOption gameListOption;
    private UserModel userModel;
    private ThirdGameModel thirdGameModel;

    private void initInfo () {
        userModel = UserModel.getInstance(this);
        userModel.registListener(userInformationChanged);

        thirdGameModel = ThirdGameModel.getInstance(this);
        thirdGameModel.registThirdGameMoneyChangedListener(thirdGameMoneyChangedListener);

        gameListOption = new GameListOption(gameListScrollView, gameListView, loadingDialog, commendGameChangedListener);

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        //home创建广播
        innerReceiver = new InnerRecevier();
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        registerReceiver(innerReceiver, intentFilter);
        //电源键关闭
        innerReceiver1 = new InnerRecevier();
        IntentFilter filter1 = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        registerReceiver(innerReceiver1, filter1);
        //电源键开启
        innerReceiver2 = new InnerRecevier();
        IntentFilter filter2 = new IntentFilter(Intent.ACTION_USER_PRESENT);
        registerReceiver(innerReceiver2, filter2);
        //播放音乐
        mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.bgm);
        //是否循环播放
        if (!mediaPlayer.isPlaying()) {
            mediaPlayer.setLooping(true);
            mediaPlayer.start();
        }

        WifiManager wifi_service = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
        wifiInfo = wifi_service.getConnectionInfo();

    }

    @Override
    //设置回退.
    public boolean onKeyDown (int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            exitByDoubleClick();
        }
        return false;
    }

    private void exitByDoubleClick () {
        Timer tExit = null;
        if (!isExit) {
            isExit = true;
            Toast.makeText(MainActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            tExit = new Timer();
            tExit.schedule(new TimerTask() {
                @Override
                public void run () {
                    isExit = false;//取消退出
                }
            }, 2000);// 如果2秒钟内没有按下返回键，则启动定时器取消掉刚才执行的任务
        } else {
            mediaPlayer.stop();
            finish();
            System.exit(0);
        }
    }

    class InnerRecevier extends BroadcastReceiver {
        final String SYSTEM_DIALOG_REASON_KEY = "reason";

        final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";

        final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";

        @Override
        public void onReceive (Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
                String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
                if (reason != null) {
                    if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
//                          Toast.makeText(MainActivity.this, "Home键被监听", Toast.LENGTH_SHORT).show();
                        mediaPlayer.stop();
                    } else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
//                        Toast.makeText(MainActivity.this, "多任务键被监听", Toast.LENGTH_SHORT).show();
                        mediaPlayer.stop();
                    }
                }
            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                // 退出程序...
                mediaPlayer.stop();
                SYSOUtils.sOut_("电源键被监听关闭");
            } else if (Intent.ACTION_USER_PRESENT.equals(action) && Constants.backgroundvoic) {
                if (!mediaPlayer.isPlaying()) {
                    //播放音乐
                    mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.bgm);
                    //是否循环播放
                    mediaPlayer.setLooping(true);
                    mediaPlayer.start();
                }
                SYSOUtils.sOut_("屏幕解锁");
            }
        }
    }

}